<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>watch监控</title>
    <script src="node_modules/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <input type="text" v-model="message"/>
    <br/><br>
    <input type="text" v-model="person.name"/><br>
    <input type="text" v-model="person.age"/><br>
    <button @click="person.age++">+</button>
    <h2>
        名字为: {{ person.name }}, 年龄为: {{ person.age }}
    </h2>
</div>
<script type="text/javascript">
    var app = new Vue({
        el: "#app",
        data: {
            message: "hello",
            person: {"name": "admin", "age": 25}
        },
        watch: {
            message(newValue, oldValue) {
                console.log("新值: " + newValue + "; 旧值: " + oldValue)
            },
            person: {
                //开启深度监控
                deep: true,
                //可以获取到最新对象的属性数据
                handler(obj) {
                    console.log("name=" + obj.name + ",age=" + obj.age)
                }
            }
        }
    });
</script>
</body>
</html>